<script type="text/javascript">
$(document).ready(function(){
	$("#lv2").live("change",function () {
          var str = "";
          $("#lv2 option:selected").each(function () {
                str += $(this).val() + " ";
              });
          $("#pid").val(str);
        })
    $("#lv1").live("change",function(){
    	var cat_id = ($(this).val());			
		if(cat_id != 0){
		
			$("<img src='images/loadingAnimation.gif' style='margin:0 0 0 5px;' />").appendTo("#tdsecond");
			$.post('admin_product_category/select_sub_category',{
				'pid' : cat_id,
				'control_name' : 'lv2'
			},function(data){
				$(".tdsecond").html(data);
			})
		}
    })
})
</script>
<h3>Product Category  [Add / Edit Form]</h3>
<div></div>
<form enctype="multipart/form-data" method="post" action="admin_product_category/save">
	<table class="tblist2">
		<tr>
			<th>Main category</th>
			<td>
				<select name="lv1" id="lv1">
					<option value="0">--select main category</option>
					<? 
						foreach($main_category as $item):
							$selected = $item['id'] == $c_main_category ? 'selected="selected"' : "";
							echo '<option value="'.$item['id'].'" '.$selected.'>'.$item['name_th'].'</option>';
						endforeach;
					?>
				</select>				
			</td>
		</tr>
		<tr>
			<th>Secondary category</th>
			<td class="tdsecond">
				<select name="lv2" id="lv2">
					<option value="0">--select secondary category</option>
					<? 
						foreach($secondary_category as $item):
							$selected = $item['id'] == $pid ? 'selected="selected"' : "";
							echo '<option value="'.$item['id'].'" '.$selected.'>'.$item['name_th'].'</option>';
						endforeach;
					?>
				</select>
				<input type="hidden" name="pid" id="pid" value="<?=@$pid;?>"/>
			</td>
		</tr>
		<tr>
			<th width="150px">Name TH</th>
			<td>
            	<input type="hidden" name="id" value="<?=@$rs['id'];?>" />
            	<input type="text" name="name_th" value="<?=@$rs['name_th'];?>" /> <span class="txtOrange">*</span>
            &nbsp;</td>
		</tr>
		<tr>
			<th>Name EN</th>
			<td>
				<input type="text" name="name_en" value="<?=@$rs['name_en'];?>" /> <span class="txtOrange">*</span>
			</td>
		</tr>
		<tr>			
			<td colspan="2" align="center">
				<input type="submit" value="Save" class=""> <input type="button" value="  Back  " onclick="history.back();"> 
			</td>
		</tr>
	</table>
</form>